/*
 * BanBu_HisFriendCell
 * @description 本文件提供个人空间点击粉丝关注进入的粉丝和关注列表的定制cell
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供个人空间点击粉丝关注进入的粉丝和关注列表的定制cell
 */

#import "BanBu_HisFriendCell.h"
#import <QuartzCore/QuartzCore.h>
#import "BanBu_ImageView.h"
#import "BanBu_NavButton.h"
#define x 90
#define featureEndx 310
#define sep 2.0
#define CELL_HEIGHT 64

#define boyColor [UIColor colorWithRed:48.0/255 green:169.0/255 blue:217.0/255 alpha:1.0]
#define girlColor [UIColor colorWithRed:252.0/255 green:192.0/255 blue:213.0/255 alpha:1.0]
@implementation BanBu_HisFriendCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CELL_HEIGHT-1, 320, 1.0)];
        lineView.backgroundColor = [UIColor colorWithRed:224.0/255 green:224.0/255 blue:224.0/255 alpha:1.0];
        [self.contentView addSubview:lineView];
        [lineView release];
        
        BanBu_ImageView *backImage = [[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeCell];
        backImage.frame = CGRectMake(0, 0, 320, CELL_HEIGHT+1);
        self.backgroundView = backImage;
        [backImage release];
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(7,7, 50, 50)];
        
        _iconView = imageView;
        _iconView.layer.cornerRadius = 25;
        _iconView.layer.masksToBounds = YES;

        _iconView.contentMode = UIViewContentModeScaleAspectFit;
		[self.contentView addSubview:_iconView];
        [imageView release];
        //vip标志
        _vipImageView = [[UIImageView alloc] initWithFrame:CGRectMake(6, 6, 52, 54)];
        
        [self.contentView addSubview:_vipImageView];
        [_vipImageView release];
        
        _greenBall = [[UIImageView alloc] initWithFrame:CGRectMake(CELL_HEIGHT-22, 2, CELL_HEIGHT/6, CELL_HEIGHT/6)];
        _greenBall.image = [UIImage imageNamed:@"onlineFlag.png"];
        _greenBall.hidden = YES;
        [imageView addSubview:_greenBall];
        [_greenBall release];
        
		_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CELL_HEIGHT+5,9, 160, CELL_HEIGHT/4)];
		_nameLabel.textAlignment = kTextAlignmentLeft;
		_nameLabel.backgroundColor = [UIColor clearColor];
		_nameLabel.font = [UIFont systemFontOfSize:14];
		[self.contentView addSubview:_nameLabel];
        [_nameLabel release];
		
        
        //年龄和性别
        _sexImgV = [[UIImageView alloc]initWithFrame:CGRectMake(145, 36, 13, 13)];
        [self.contentView addSubview:_sexImgV];
        [_sexImgV release];
        
        _ageLabel = [[UILabel alloc]initWithFrame:CGRectMake(161, 34, 50, 16)];
        _ageLabel.backgroundColor = [UIColor clearColor];
		_ageLabel.font = [UIFont systemFontOfSize:13];
		_ageLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
		[self.contentView addSubview:_ageLabel];
        [_ageLabel release];
        
        //距离显示
        _distanceBack = [[UIImageView alloc]initWithFrame:CGRectMake(68, 38, 10, 14)];
        NSString *signatureBackpath = [[NSBundle mainBundle] pathForResource:@"distance_mark" ofType:@"png"];
        _distanceBack.image =  [UIImage imageWithContentsOfFile:signatureBackpath];
        [self.contentView addSubview:_distanceBack];
        [_distanceBack release];
        _distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(81, 37, 49, 16)];
        _distanceLabel.textAlignment = kTextAlignmentCenter;
		_distanceLabel.backgroundColor = [UIColor clearColor];
		_distanceLabel.font = [UIFont systemFontOfSize:13];
		_distanceLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
		[self.contentView addSubview:_distanceLabel];
        [_distanceLabel release];

        
        //视频认证用户标志
        NSString *verifypath = [[NSBundle mainBundle] pathForResource:@"verify_card" ofType:@"png"];
        _verify = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:verifypath]];
       
        _verify.frame = CGRectMake(188, 37.5, 15, 10);
        
        _verify.hidden = YES;
        [self.contentView addSubview:_verify];
        [_verify release];
        
        _linkBtn = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeCustomBtn];
        _linkBtn.frame = CGRectMake(__MainScreen_Width-50, (CELL_HEIGHT-40)/2, 40, 40);
        _linkBtn.titleLabel.font = [UIFont boldSystemFontOfSize:23];
        [self.contentView addSubview:_linkBtn];
        [_linkBtn release];
        
    }
    return self;
}

#pragma mark - 更新cell显示数据
/**
 * @函数名称：updateHisFriendCell:
 * @函数描述：更新cell显示数据
 * @输入参数：(NSDictionary *)buddy
 * @输出参数：nil
 * @返回值：nil
 * @author：yinlinlin
 */
//2014年09月02日15:31:11 更新cell显示
- (void)updateHisFriendCell:(NSDictionary *)buddy
{
    NSDictionary * infoDict = [buddy valueForKey:keyPersonalInfo];
   //头像
    [_iconView setImageWithURL:[NSURL URLWithString:[infoDict valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
    
    _nameLabel.text = [MyAppDataManager IsInternationalLanguage:[infoDict valueForKey:@"pname"]];
 
    _distanceLabel.text = [NSString stringWithFormat:@"%@",[infoDict valueForKey:@"dmeter"]];
    [_distanceLabel sizeToFit];
    //年龄和性别
    NSString *sexpath = [[NSBundle mainBundle] pathForResource:[infoDict valueForKey:@"gender"] ofType:@"png"];
    _sexImgV.image =  [UIImage imageWithContentsOfFile:sexpath];
    _ageLabel.text = [infoDict valueForKey:@"oldyears"];
    [_sexImgV setFrame:CGRectMake(91 + _distanceLabel.frame.size.width, 37, 13, 13)];
    [_ageLabel setFrame:CGRectMake(106 + _distanceLabel.frame.size.width, 36, 30, 16)];
    [_verify setFrame:CGRectMake(131 + _distanceLabel.frame.size.width, 38.5, 15, 10)];
    //vip等级显示
    //vip
    if ([[infoDict valueForKey:@"userlevel"] integerValue]>0)
    {
        NSString *path = [[NSBundle mainBundle] pathForResource:@"verify_vip" ofType:@"png"];
        _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
        [_verify setHidden:NO];
    }
    else
    {
        //视频认证用户
        if ([[infoDict valueForKey:@"verify"] boolValue])
        {
            NSString * verifySource = [NSString stringWithFormat:@"verify_%@",[infoDict valueForKey:@"gender"]];
            NSString *path = [[NSBundle mainBundle] pathForResource:verifySource ofType:@"png"];
            _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
            [_verify setHidden:NO];
        }
        else
        {
            [_verify setHidden:YES];
            NSString *path = [[NSBundle mainBundle] pathForResource:@"verify_normal" ofType:@"png"];
            _vipImageView.image =  [UIImage imageWithContentsOfFile:path];
        }
    }
    
    
    //在线
    NSTimeInterval _time = [MyAppDataManager getTheSecondLastOnlineTime:[infoDict valueForKey:@"ltime"]];
    if(_time<=900)
    {
        _greenBall.hidden = NO;
    }
    else
    {
        _greenBall.hidden = YES;
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    if(self.highlighted)
    {
        _nameLabel.textColor = [UIColor whiteColor];
        _ageLabel.textColor = [UIColor whiteColor];
        _distanceLabel.textColor = [UIColor whiteColor];
    }
    else
    {
        _nameLabel.textColor = [UIColor blackColor];
        _ageLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
        _distanceLabel.textColor = UIColorWithRGB(150, 150, 150, 1.0);
    }
}


-(void)cancelImageLoad{
    
    [_iconView cancelCurrentImageLoad];
    _iconView.image = nil;
}

- (void)willMoveToSuperview:(UIView *)newSuperview {
	[super willMoveToSuperview:newSuperview];
	if(!newSuperview) {
		[self cancelImageLoad];
	}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
}

- (void)dealloc
{
    [_features release],_features = nil;
    [super dealloc];
}

@end
